import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:news_flutter/pages/community/circle_all.dart';
import 'package:news_flutter/pages/community/circle_rec.dart';
import 'package:news_flutter/utils/my_navigator.dart';
import 'package:news_flutter/utils/precompile.dart';
import 'package:news_flutter/widgets/custom/my_diver_widget.dart';

class CommunityIndexPage extends StatefulWidget {
  @override
  _CommunityIndexPageState createState() => _CommunityIndexPageState();
}

class _CommunityIndexPageState extends State<CommunityIndexPage> with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin{
  @override
  bool get wantKeepAlive => true;
  TabController _tabController;
  List _tabBarMenus =["推荐","广场"];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(
      length: _tabBarMenus.length,
      vsync: this,
    );
  }
  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiOverlayStyle.dark,
      child: Scaffold(
        body: SafeArea(
          child: Column(
            children: <Widget>[
              _tabBar(),
              Expanded(
                child: _tabBarView(),
              ),
            ],
          ),
        ),
      ),
    );
  }
  //tabbar
  Widget _tabBar() {
    return Container(
      height: kToolbarHeight,
      child: Column(
        children: <Widget>[
          Expanded(
            child: TabBar(
              //设置tab是否可水平滑动
              isScrollable: true,
              //控制器
              controller: _tabController,
              indicatorColor: Colors.black,
              indicatorSize: TabBarIndicatorSize.label,
              indicatorWeight: 2,
              labelStyle: TextStyle(fontSize: 18,fontWeight: FontWeight.bold),
              labelColor: Colors.black,
              unselectedLabelColor: MyColor.TEXT_GRAY,
              indicatorPadding: EdgeInsets.symmetric(horizontal: 15),
              tabs: _tabBarMenus.map((item) {
                return Container(
                  margin: EdgeInsets.only(left: 10, right: 10),
                  child: Tab(text: item),
                );
              }).toList(),
            ),
          ),
          MyDiver(),
        ],
      ),
    );
  }
  Widget _tabBarView() {
    List <Widget> children =[];
    children.add(CircleRecPage());
    children.add(CircleAllPage());
    return TabBarView(
      controller: _tabController,
      children: children,
    );
  }
}
